package erfgame.core.memory;

public final class Pointer<To> {
	
	private InMemoryObject<To> to;
	
	public Pointer( InMemoryObject<To> to ){
		this.to = to;
	}
	
	public To getValue() {
		return this.to.getValue();
	}
	
	public Pointer<To> assign() {
		return to.createPointer();
	}
	
	public void free(){
		if( to != null ){
			to.releasePointer(this);
			to = null;
		}
	}

	@Override
	protected void finalize() throws Throwable {
		free();
		super.finalize();
	}
	
}
